import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qf.automation.user.UserApplication;
import com.qf.automation.user.service.UserService;
import com.qf.automation.user.controller.SysInfoAcquirerService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest(classes =UserApplication.class)
@RunWith(SpringRunner.class)
@AutoConfigureMockMvc
public class text {
    @Resource
    private UserService userService;

    @Test
    public void m() {
//       String s = userService.randomNickName();
//       System.out.println(s);
//       ArrayList arrayList=new ArrayList();
//       1050元  分配给10个人

        BigDecimal bigDecimal = new BigDecimal(1050);
        BigDecimal bigDecimal1 = new BigDecimal(10);
        BigDecimal divide = bigDecimal.divide(bigDecimal1);
        System.out.println(1050 / 10);

    }

    @Test
    public void m2() {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8};

        int i = 5;
        int min = 0;
        int max = arr.length - 1;
        int maa = 0;
        while (min <= max) {
            maa = (min + max) / 2;
            if (i < arr[maa]) {
                max = maa - 1;
            } else if (i > arr[maa]) {
                min = maa + 1;
            } else if (i == arr[maa]) {
                System.out.println("下标为" + (maa - 1));
                return;
            }
        }
        System.out.println("没找到");

    }

    @Test
    public void m3() {
        int[] arr = {9, 1, 7, 5, 4, 6, 2, 8, 3};
        for (int i = 0; i < arr.length - 1; i++) {
            int k = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[k] < arr[j]) {
                    k = j;
                }
            }
            if (k != i) {
                arr[i] = arr[i] ^ arr[k];
                arr[k] = arr[i] ^ arr[k];
                arr[i] = arr[i] ^ arr[k];
            }
            System.out.println(Arrays.toString(arr));
        }


    }

    @Test
    public void m4() {
        int[] arr = {9, 1, 7, 5, 4, 6, 2, 8, 3};
        int a = 0;
        int b = arr.length;
        m44(arr, a, b - 1);
        System.out.println(Arrays.toString(arr));
    }

    private static void m44(int[] arr, int a, int b) {
        if (a >= b) {
            return;
        }
        int n = a;
        int m = b;
        for (; a < b; ) {
            for (; a < b; b--) {
                if (arr[a] > arr[b]) {
                    arr[b] = arr[a] ^ arr[b];
                    arr[a] = arr[a] ^ arr[b];
                    arr[b] = arr[a] ^ arr[b];
                    a++;
                    break;
                }
            }
            for (; a < b; a++) {
                if (arr[a] > arr[b]) {
                    arr[b] = arr[a] ^ arr[b];
                    arr[a] = arr[a] ^ arr[b];
                    arr[b] = arr[a] ^ arr[b];
                    b--;
                    break;
                }
            }
        }
        m44(arr, n, a - 1);
        m44(arr, a + 1, m);

    }

    @Test
    public void mmm() {
//       int[] arr={2,1,1,2};
//        TreeSet<Integer> set=new TreeSet<>();
//        for (int i=0;i<arr.length;i++) {
//            set.add(arr[i]);
//        }
//        for (Integer integer:set){
//            System.out.println(integer);
//        }
        String a = "132135r32433431";
        HashMap<String, Integer> map = new HashMap<>();

        String[] split = a.split("");
        for (int i = 0; i < split.length; i++) {
            if (map.containsKey(split[i])) {
                Integer integer = map.get(split[i]);
                map.put(split[i], integer + 1);
            } else {
                map.put(split[i], 1);
            }
        }
        Integer i = 0;
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (entry.getValue() > i) {
                i = entry.getValue();
            }
//            System.out.println(entry.getKey()+"....."+entry.getValue());
        }
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (entry.getValue() == i) {
                System.out.println(entry.getKey() + "....." + entry.getValue());
            }
        }
    }
    @Test
    public void  mmm1(){
        int i=10;
        int b = b(i);
        System.out.println(b);
    }
    public int b(int i){

        if (i<2){
            return i;
        }
        int x=b(i-1)+b(i-2);
        return x;
    }
    public void mmm3(){
        JSONObject jsonObject = JSON.parseObject(new SysInfoAcquirerService().getNetworkThroughput());
        String txPercent = jsonObject.getString("txPercent");
        String rxPercent = jsonObject.getString("rxPercent");
        System.out.println(txPercent);
        System.out.println(rxPercent);
    }
    @Test
    public void m1(){
        BigDecimal bigDecimal=new BigDecimal("123");
        bigDecimal=bigDecimal.divide(new BigDecimal("10000"));
        bigDecimal=bigDecimal.divide(new BigDecimal("22"),4,BigDecimal.ROUND_HALF_UP);
        bigDecimal=bigDecimal.remainder(new BigDecimal("100"));
        double v = bigDecimal.doubleValue();
        double s=0.0000559;
        System.out.println(s);
        System.out.println(bigDecimal.doubleValue()+"");
        System.out.println(bigDecimal.toString());
    }

}
